{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "连接成功\n",
      "<xtquant.xttype.StockAccount object at 0x0000025945D4EC50>\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "from xtquant.xttrader import XtQuantTrader\n",
    "\n",
    "# miniQMT安装路径\n",
    "mini_qmt_path = r'D:\\国金证券QMT交易端\\userdata_mini'\n",
    "# 创建session_id\n",
    "session_id = int(random.randint(100000, 999999))\n",
    "# 创建交易对象\n",
    "xt_trader = XtQuantTrader(mini_qmt_path, session_id)\n",
    "# 启动交易对象\n",
    "xt_trader.start()\n",
    "# 连接客户端\n",
    "connect_result = xt_trader.connect()\n",
    "\n",
    "if connect_result == 0:\n",
    "    print('连接成功')\n",
    "\n",
    "from xtquant.xttype import StockAccount\n",
    "# QMT账号\n",
    "account_id = '1010573943'\n",
    "# 创建账号对象\n",
    "account = StockAccount(account_id)\n",
    "# 订阅账号\n",
    "res = xt_trader.subscribe(account)\n",
    "print(account)\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号类型: 2\n",
      "资金账号: 1010573943\n",
      "证券代码: 600461.SH\n",
      "委托类型: 24\n",
      "成交编号: 33081508\n",
      "成交时间: 1712904276\n",
      "成交均价: 10.18\n",
      "成交数量: 100\n",
      "成交金额: 1018.0\n",
      "订单编号: 0\n",
      "柜台合同编号: 78194\n"
     ]
    }
   ],
   "source": [
    "trades = xt_trader.query_stock_trades(account)\n",
    "for trade in trades:\n",
    "    print('账号类型:', trade.account_type)\n",
    "    print('资金账号:', trade.account_id)\n",
    "    print('证券代码:', trade.stock_code)\n",
    "    print('委托类型:', trade.order_type)\n",
    "    print('成交编号:', trade.traded_id)\n",
    "    print('成交时间:', trade.traded_time)\n",
    "    print('成交均价:', trade.traded_price)\n",
    "    print('成交数量:', trade.traded_volume)\n",
    "    print('成交金额:', trade.traded_amount)\n",
    "    print('订单编号:', trade.order_id)\n",
    "    print('柜台合同编号:', trade.order_sysid)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "miniqmt-demo-cptEsqYo-py3.10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
